import requests
import time
import execjs
from PIL import Image


def get_session():
    t = str(int(time.time()*1000))
    url = 'https://www.jdl.cn/ecology/getSession?_={}'.format(t)
    headers = {
        "user-agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36"
    }
    res = requests.get(url,headers=headers)
    print(res.text)
    session = res.json()['obj']
    print(session)
    ct = execjs.compile(open(r"E:/nodeProject/js/jd_yzm.js",encoding='UTF-8').read()).call('data',session)
    print(ct)

def get_yzm(session, ct):
    url = 'https://jcap.m.jd.com/cgi-bin/api/fp?si=%s&ct=%s&version=2&lang=1&client='%(session,ct)
    # data = {
    #     "si":session,
    #     "ct":ct,
    #     "version":"2",
    #     "lang":"1",
    #     "client":""
    # }
    headers = {
        'authority': 'jcap.m.jd.com',
        'method': 'POST',
        'path': '/cgi-bin/api/fp',
        'scheme': 'https',
        'accept': 'application/json, text/plain, */*',
        'accept-encoding': 'gzip, deflate, br',
        'accept-language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7',
        'cache-control': 'no-cache',
        'content-type': 'application/x-www-form-urlencoded;charset=UTF-8',
        'origin': 'https://www.jdl.cn',
        'pragma': 'no-cache',
        'referer': 'https://www.jdl.cn/',
        'sec-fetch-dest': 'empty',
        'sec-fetch-mode': 'cors',
        'sec-fetch-site': 'cross-site',
        'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36',
    }
    # res = requests.get(url,headers=headers)
    # print(res.text)

# url = 'https://jcap.m.jd.com/cgi-bin/api/check'
def change_size(png_path, height, width,out_path):
    png = Image.open(png_path)
    png = png.resize((height, width),Image.ANTIALIAS)
    png.save(out_path)


if __name__ == "__main__":
    change_size("E:/nodeProject/python/jd_yzm.png",179,290,"E:\nodeProject\python\jj.png")
    change_size("E:/nodeProject/python/jd_yzm_1.png",109,37,"E:\nodeProject\python\jj.png")


